package org.jeecg.modules.cshonlinebusiness.controller;

import java.util.Arrays;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.cshonlinebusiness.entity.CshRescueOrderEntity;
import org.jeecg.modules.cshonlinebusiness.service.ICshRescueOrderEntityService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * @Description: csh_rescue_order
 * @Author: zhaodui
 * @Date:   2020-03-31
 * @Version: V1.0
 */
@RestController
@RequestMapping("/csh/cshrescueoeder")
@Slf4j
@Api(tags="救援订单")
public class CshRescueOrderEntityController extends JeecgController<CshRescueOrderEntity, ICshRescueOrderEntityService> {
	@Autowired
	private ICshRescueOrderEntityService cshRescueOrderEntityService;
	
	/**
	 * 分页列表查询
	 *
	 * @param cshRescueOrderEntity
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@ApiOperation("救援订单分页")
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public Result<?> queryPageList(CshRescueOrderEntity cshRescueOrderEntity,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<CshRescueOrderEntity> queryWrapper = QueryGenerator.initQueryWrapper(cshRescueOrderEntity, req.getParameterMap());
		Page<CshRescueOrderEntity> page = new Page<CshRescueOrderEntity>(pageNo, pageSize);
		IPage<CshRescueOrderEntity> pageList = cshRescueOrderEntityService.page(page, queryWrapper);
		return Result.ok(pageList);
	}
	
	/**
	 *   添加
	 *
	 * @param cshRescueOrderEntity
	 * @return
	 */
	@ApiOperation("救援订单添加")
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public Result<?> add(@RequestBody CshRescueOrderEntity cshRescueOrderEntity) {
		cshRescueOrderEntityService.save(cshRescueOrderEntity);
		return Result.ok("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param cshRescueOrderEntity
	 * @return
	 */
	@ApiOperation("救援订单编辑")
	@RequestMapping(value = "/edit", method = RequestMethod.POST)
	public Result<?> edit(@RequestBody CshRescueOrderEntity cshRescueOrderEntity) {
		cshRescueOrderEntityService.updateById(cshRescueOrderEntity);
		return Result.ok("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@ApiOperation("救援订单删除")
	@RequestMapping(value = "/delete", method = RequestMethod.POST)
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
		cshRescueOrderEntityService.removeById(id);
		return Result.ok("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@ApiOperation("救援订单批量删除")
	@RequestMapping(value = "/deleteBatch", method = RequestMethod.POST)
	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.cshRescueOrderEntityService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.ok("批量删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@ApiOperation("救援订单查询")
	@RequestMapping(value = "/queryById", method = RequestMethod.GET)
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		CshRescueOrderEntity cshRescueOrderEntity = cshRescueOrderEntityService.getById(id);
		if(cshRescueOrderEntity==null) {
			return Result.error("未找到对应数据");
		}
		return Result.ok(cshRescueOrderEntity);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param cshRescueOrderEntity
    */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, CshRescueOrderEntity cshRescueOrderEntity) {
        return super.exportXls(request, cshRescueOrderEntity, CshRescueOrderEntity.class, "csh_rescue_order");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, CshRescueOrderEntity.class);
    }

}
